package com.bdqn.controller;

import com.bdqn.pojo.User;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.nio.channels.Pipe;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Author 27435
 * @Date 2024/12/2315:22
 * @Version 1.0
 */

@Controller
public class HelloController {
    @RequestMapping("/hello")
    @ResponseBody
    public String hello(User user){
        // 基本参数（1 2 个参数）
//        System.out.println(name);
//        System.out.println(age);
        System.out.println(user);
        return "hello mvc";
    }

    @RequestMapping("/arr")
    @ResponseBody
    public String array(String [] arrs){
//        for (String arr : arrs) {
//            System.out.println(arr);
//        }
        System.out.println(arrs);
        return "hello arrays";
    }

    @RequestMapping("array")
    @ResponseBody
    public String arrayTest(String [] likes){
        System.out.println(Arrays.toString(likes));
        return "{'code':'ok'}";
    }

    @RequestMapping("/list")
    @ResponseBody
    public String list(@RequestParam("likes") List<String> likes){
        for (String arr : likes) {
            System.out.println(arr);
        }
        return "hello likes";
    }

    @RequestMapping("/map")
    @ResponseBody
    public String mapTest(@RequestParam Map<String, String> maps){
        System.out.println(maps);
        return "{'code':'map ok'}";
    }

    @RequestMapping("/date")
    @ResponseBody
    public String getDate(Date date, @DateTimeFormat(pattern = "yyyy-MM-dd") Date date2,
                          @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date date3){
        System.out.println("date:" + date);
        System.out.println("date2:" + date2);
        System.out.println("date3:" + date3);
        return "data mvc";
    }
}
